﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace QuangMobile
{
    public partial class UCProductBlock : System.Web.UI.UserControl
    {
        private string _Title;
        private DataTable _ListProduct;

        public DataTable ListProduct
        {
            get { return _ListProduct; }
            set { _ListProduct = value; }
        }

        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        public UCProductBlock() { }
        public UCProductBlock(string bTitle, DataTable bData)
        {
            this._Title = bTitle;
            this._ListProduct = bData;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BlockTitle.Text = Title;
            BlockContent.Controls.Clear();
            for (int i = 0; i < ListProduct.Rows.Count; i++)
            {
                UCProductItem Item = (UCProductItem)LoadControl("UCProductItem.ascx");
                Item.ProductID = Convert.ToInt32(ListProduct.Rows[i]["ID"]);
                if (ListProduct.Rows[i]["AnhSP"] == DBNull.Value)
                {
                    Item.ProductImage = "../upload/no-image.png";
                }
                else
                {
                    Item.ProductImage = ListProduct.Rows[i]["AnhSP"].ToString();
                }
                Item.ProductTitle = ListProduct.Rows[i]["TenSP"].ToString();
                Item.ProductPrice = Convert.ToDouble(ListProduct.Rows[i]["GiaSP"]);
                Item.ProductComment = ListProduct.Rows[i]["MoTa"].ToString();
                BlockContent.Controls.Add(Item);
                Item = null;
            }
        }
    }
}